Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update forked module name, paths, and docs to be imported; support for applying multiple options in a TermRendererOption #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

andyfeller
Copy link

This pull request is primarily about getting this fork in a state that it can be imported for cli/go-gh experimentation by updating the module name and resulting import paths. As this fork is not meant to be long lived, the README has been updated to dissuade visitors from reusing this in their projects.

Additionally, this pull request introduces the WithOptions(options ...TermRendererOption) TermRendererOption, which is helps users apply multiple options while still adhering to the WithXXXX() TermRendererOption pattern while not having direct access to rendering code.

`WithOptions(...TermRendererOption) TermRendererOption` function is a solution for users who follow the `WithXXX() TermRendererOption` pattern but need to apply multiple options but are not directly responsible for rendering.
This is a temporary fork to allow the GitHub CLI to experiment with deeper integration with charmbracelet/glamour; it is not meant to be long lived.

This commit is meant to give clear understanding as we want to collaborate with the Charm team to improve Glamour.
andyfeller added a commit to cli/go-gh that referenced this pull request Feb 25, 2025
This commit is focused on PR feedback around codeblock testing and simplifying related code:

1. Use of new `WithOptions(...TermRendererOption) TermRendererOption` to clean up `WithTheme()`

   The `glamour` TermRendererOption pattern has a limitation that users cannot compose multiple options without duplicating code or building one-off anonymous functions.

   However, this commit takes advantage of an enhancement in cli/glamour#3 that allows users to leverage a helper to avoid building one-offs.

1. Use of new `leaanthony/go-ansi-parser` dependency for parsing ANSI escape sequences and display attributes

   In v1 of `markdown_test.go`, the codeblock tests were very simple, testing the result of output of markdown rendering against a string of ANSI escape sequences. The concern raised is that this was testing the result rather than behavior wanted.

   In v2 of `markdown_test.go`, the codeblock tests were refactored to use regex to extract and analyze ANSI escape sequences and display attributes. The concern raised was that this was a lot of logic to build and maintain and might benefit from a dependency that could do it.

   In v3 of `markdown_test.go`, a combination of v1 and v2 approaches for 1) testing that theme appropriate colors are used and 2) testing that ensures accessible display options are used when accessible experience is enabled
Copy link

@jtmcg jtmcg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants